package com.ay.shardingshere.mapper;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Author: ay
 * @Date: 2021/6/30
 * @Description: sharding-jdbc 单库两表操作
 **/
@Mapper
@Component
public interface ShardingOrderMapper {

    /**
     * 单库两表保存订单信息
     */
    @Insert("insert into sharding_order(order_id,order_type,cust_id,cust_type,cust_email,payment_method_type,payment_provider_id,shipping_method_type,packing_type,preferred_shipping_time_type,receiver_name,receiver_address,receiver_country_id,receiver_province_id,receiver_city_id,receiver_zip,receiver_tel,receiver_mobile_tel,cust_message) VALUES (0, 10, 1, 'xzbt_yxd@163.com', 1, 6, 1, 0, 3, 'ttt ttt', '北京市朝阳区佳程广场', 9000, 111, 1, '100011', '51236117', ' ', ' ')")
    void save();

    /**
     * 单库两表更新订单信息
     * @param id
     */
    @Update("update sharding_order SET order_type=0,cust_id=10,cust_type=1,cust_email='xiaodong.yang@partner.bmw-brilliance.cn' where id = #{id}")
    void update(Long id);

    /**
     * 单库两表查询订单信息
     * @param modulo
     * @return
     */
    @Select("select a.id,order_id,order_type,cust_id,cust_type,cust_email,payment_method_type,payment_provider_id,shipping_method_type,packing_type,preferred_shipping_time_type,receiver_name,receiver_address,receiver_country_id,receiver_province_id,receiver_city_id,receiver_zip,receiver_tel,receiver_mobile_tel,cust_message from sharding_order a where a.id % 100 = #{modulo}")
    List<Map<String,Object>> list(Integer modulo);

    /**
     * 截断表
     */
    @Delete("Truncate table sharding_order")
    void truncateTable();
}
